module AuthenticatedSystem
	def current_user=(new_user)
		session[:user_id] = new_user ? new_user.id : nil
		new_user
	end

	def current_user
		p "adsfas"
		user_id = session[:user_id]
		if user_id.blank?
			p "dddd"
			user_id = params[:client_id]
			puts "params: #{params.inspect}"
			session[:user_id] = user_id
		end

		return nil if user_id.blank?	
		@current_user = @current_user || User.find(user_id)
		@current_user
	end

	def sign_in(user_name,password)
		self.current_user = User.first(:conditions => {
			:user_name => user_name,
			:password => password
		})	
		puts "current_user = #{current_user}"	
		self.current_user		
	end

	def sign_out
		session[:user_id] = nil
	end
end